package com.example.client;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.net.URI;
import java.net.URISyntaxException;

@SpringBootApplication
public class ClientApplication implements CommandLineRunner {



	public static void main(String[] args) throws URISyntaxException {
		SpringApplication.run(ClientApplication.class, args);
		for (int i = 2000;i<7000;i++){

			String url = "http://116.205.254.65:18080/create?userName="+"测试"+i +"&pwd=123&head=head";
			String result1 = HttpUtil.get(url);
			JSONObject jsonObject = JSON.parseObject(result1);
			String token = jsonObject.getString("token");
			URI uri = new URI("ws://116.205.254.65:18090//websocket?token="+token);
			WebsocketRunClient test = new WebsocketRunClient(uri, "test"+i);
			test.connect();
			test.setConnectionLostTimeout(1110);
		}



//		HBReq.Builder builder = HBReq.newBuilder();
//		byte[] byteArray = builder.build().toByteArray();
//		ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES + byteArray.length);
//		buffer.putInt(MsgId.HB);
//		buffer.put(byteArray);
//
//		System.out.println();
//		test.send(buffer.array());
	}

	@Override
	public void run(String... args) throws Exception {
//		MatchReq.Builder builder = MatchReq.newBuilder();
//		builder.setRoomType(1);
//		byte[] byteArray = builder.build().toByteArray();
//		ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES + byteArray.length);
//		buffer.putInt(MsgId.MATCH);
//		buffer.put(byteArray);
//
//		test.send(buffer.array());
	}
}
